#include <stdio.h>

#define BUFSIZE 32
int mycopy(const char *f1,  const char *f2);

int main(int argc, char *argv[])
{
	if(argc < 3){
		return -1;
	}
	mycopy(argv[1], argv[2]);

	return 0;
}

int mycopy(const char *f1,  const char *f2)
{
	FILE * fp1 = NULL;
	FILE * fp2 = NULL;
	int c = 0;
	char buf[BUFSIZE] = {0};
	char *p = NULL;

	fp1 = fopen(f1, "r");
	if(fp1 == NULL){
		return -1;
	}
	fp2 = fopen(f2, "w");
	if(fp2 == NULL){
		fclose(fp1);
		return -1;
	}

	while(1){
		/*
		按字符复制
		c = fgetc(fp1);
		if(c == EOF){
			break;
		}
		fputc(c, fp2);
		*/

		/*
		按文件复制
		if(fgets(buf, BUFSIZE, fp1) == NULL){
			if(ferror(fp1)){
				return -1;
			}
			break;
		}
		fputs(buf, fp2);
		*/

		//按结构复制
		c = fread(buf, 1, BUFSIZE, fp1);
		if(0 == c){
			if(ferror(fp1)){
				return -1;
			}
			break;
		}
		fwrite(buf, 1, c, fp2);
	}
	fclose(fp1);
	fclose(fp2);
	return 0;
}

